var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    list:[],
    page:0,
  },
  
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    var data = {};
    //同城卡
    app.ihttpGet('https://www.58zltc.com/api.php/Shop/haveTCCard/openid/' + app.globalData.openid, function (res) {
      console.log()
      if (res.data.have_car == 0) {
        wx.showModal({
          title: '提示',
          content: '还没有开通同城卡，是否开通？',
          success: function (res) {
            if (res.confirm) {
              wx.navigateTo({
                url: '/pages/shop/tccar/tccar',
              })
            } else if (res.cancel) {
              wx.navigateBack({})
            }
          }
        })
        return false;
      }
    });
    data.openid = app.globalData.openid;
    app.ihttpPost('https://www.58zltc.com/api.php/Quan/chatList', data, function (res) {
      that.setData({
        list: res.data
      });
      
    })
  },
  backto:function(e){
    wx.navigateBack({
    })
  },
  send: function (e) {
   
  },
  chat: function (e) {
    var openid = e.currentTarget.dataset.openid;
    wx.navigateTo({
      url: 'chatroom?openid=' + openid,
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    let that = this;
    that.setData({
      page:0
    });
    var data = {};
    data.tab = that.data.tabIndex;
    data.page = that.data.page;
    app.ihttpPost('https://www.58zltc.com/api.php/Quan/getFriendList', data, function (res) {
      if(res.data.length <= 0){
        that.setData({
          isBottom: 1
        })
      }
      that.setData({
        list: res.data
      });
      wx.showToast({
        title: "已刷新"
      })
    })
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    let that = this;
    var newPage = that.data.page + 1;
    that.setData({
      page: newPage
    });
    var data = {};
    data.tab = that.data.tabIndex;
    data.page = that.data.page;
    app.ihttpPost('https://www.58zltc.com/api.php/Quan/getFriendList', data, function (res) {
      that.setData({
        list: that.data.list.concat(res.data)
      });
    })
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  }
})